package org.example.everyday;

/**
 * <p>
 * Description:TODO 详细描述
 * <p>
 * <p>
 *
 * @author anlu
 * @date 2022/6/17 8:50
 */
public class Lc1089 {
    public static void main(String[] args) {
        Lc1089 lc1089 = new Lc1089();
        int[] nums = {1,0,2,3,0,4,5,0};
        lc1089.duplicateZeros(nums);
        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }

    public void duplicateZeros(int[] arr) {
        int n = arr.length;
        int top = 0;
        int i = -1;
        while (top < n){
            i++;
            if(arr[i] != 0){
                top++;
            }else{
                top += 2;

            }
        }
        int j = n - 1;
        if(top == n + 1){
            arr[j] = 0;
            j--;
            i--;
        }
        while (j >= 0){
            arr[j] = arr[i];
            j--;
            if(arr[i] == 0){
                arr[j] = arr[i];
                j--;
            }
            i--;
        }
    }
}
